#!/bin/bash

:<<eof

1. 语法格式

name()
{
    command1..
    command2..
    command3..
}

function name
{
    command1..
    command2..
    command3..
}

2. 调用函数

直接调用函数名，函数内部可以直接使用参数$1,$2,...$name

function_name $1 $2

eof


# 命令出错会停止执行
set -e
# 打印每条执行的命令
set -x

# 监控nginx进程是否挂掉，挂了，重新拉起


this_pid=$$

while true
do
    status=`ps -ef | grep nginx | grep -v grep | grep -v $this_pid` &> /dev/null
    if [ status -eq 0 ];then
        echo "nginx is running"
    else
        systemctl start nginx
        echo "nginx is down. Start it..."
    fi
done


set +x
